package org.istt.dao;

import java.io.Serializable;
import java.util.List;

import org.displaytag.properties.SortOrderEnum;

/**
 * Data Access Object (Dao) interface.   This is an empty interface
 * used to tag our Dao classes.  Common methods for each interface
 * could be added here.
 *
 * @author Matt Raible
 */
public interface Dao<T, ID extends Serializable> {
	T findById(ID id, boolean lock);

    List<T> findAll();

    List<T> findByExample(T exampleInstance, String... excludeProperty);
    
    List<T> findSimilarTo(T exampleInstance, String... excludeProperty);

    T makePersistent(T entity);

    void makeTransient(T entity);
    
    void removeEntities(List<T> entities);
    
    void saveEntities(List<T> entities);
    
    List<T> getAllRecordsPage(Class<T> clazz, int firstResult, int maxResults,
            SortOrderEnum sortDirection, String sortCriterion);
    
    int getAllRecordsCount(Class<T> clazz);
    
    /**
     * Affects every managed instance in the current persistence context!
     */
    void flush();

    /**
     * Affects every managed instance in the current persistence context!
     */
    void clear();
    
    /**
     * Whether fields is unique
     * @param fields fields which has unique constraint
     * @param value value of each field
     * @param id primary key
     * @return <code>true</code> if valid for unique constraint otherwise <code>false</code>
     */
    boolean isUnique(String[] fields, String[] value, ID id);
}
